public class text2 {
    public static void main(String[] args) {
        // 1. 字符串连接
        String s1 = "Hello";
        String s2 = "world";
        String s3 = s1 + " " + s2;
        System.out.println("Concatenation: " + s3);

        // 2. 获取字符串相关信息
        System.out.println("length : " + s3.length());
        System.out.println("Character at index 2: " + s3.charAt(2));

        // 3. 字符串比较
        String s4 = "hello world";
        System.out.println("Comparison (case sensitive): " + s3.equals(s4));
        System.out.println("Comparison (case insensitive): " + s3.equalsIgnoreCase(s4));

        // 4. 字符串替换
        String s5 = s3.replace("World","Java");
        System.out.println("Replacement: " + s5);

        // 5. 字符串分割
        String[] parts = s3.split(" ");
        System.out.print("Split: ");
        for(String part : parts){
            System.out.print(part + " ");
        }

        // 6. 大小写转换
        System.out.println("\nToUpperCase: " + s3.toUpperCase());
        System.out.println("ToUpperCase: " + s3.toLowerCase());

        // 7. 去除字符串首末空格
        String s6 = " trimmed string ";
        System.out.println("Trimmed : " + s6.trim());

        // 使用 StringBuffer 进行字符串拼接
        StringBuffer sb = new StringBuffer();
        sb.append("This ");
        sb.append("is ");
        sb.append("a ");
        sb.append("StringBuffer!");
        System.out.println("StringBuffer: " + sb.toString());
    }
}
